<?php
/**
 * @link https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
 */
namespace MobileHome\Controller;

class WechatController extends BaseController
{

    public function ajaxGetSignPackageAction()
    {
        $return = array('code' => 200, 'message' => '');
        vendor('Wechat.Jssdk', '', '.class.php');
        $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
        $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
        $cachePath = RUNTIME_PATH;
        $jssdk = new \JSSDK(C('WECHAT.AppID'), C('WECHAT.AppSecret'), $url, $cachePath);
        $signPackage = $jssdk->GetSignPackage();
        $jsApiList = ['onMenuShareTimeline', 'onMenuShareAppMessage', 'chooseImage', 'uploadImage'];
        $config = [
            'debug'     => false,
            'appId'     => C('WECHAT.AppID'),
            'timestamp' => $signPackage['timestamp'],
            'nonceStr'  => $signPackage['nonceStr'],
            'signature' => $signPackage['signature'],
            'jsApiList' => $jsApiList,
        ];
        $return['data'] = $config;
        $return['share_data'] = $this->_getShareContent();
        $this->ajaxReturn($return);
    }

    /**
     * 获取微信分享数据
     * @todo 暂时无用
     */
    private function _getShareContent()
    {
        $config = [
            'url' => C('SITE_URL'),
            'title' => '养老就在家门口!',
            'desc' => '养老就在家门口',
            'shareimg' => C('SITE_URL') . '/Public/MobileHome/images/share_logo.jpeg',
        ];
        return $config;
    }
}